let gulp     = require("gulp");
let cleanCss = require("gulp-clean-css");
let rename   = require('gulp-rename');
let concat   = require("gulp-concat");
let babel    = require("gulp-babel");
let uglify   = require('gulp-uglify');
let connect  = require('gulp-connect');
let {paths}  = require('./gulp.config');
let devConfig= require('./gulp.dev');  



function buildConfig(){
    function styles(){
        return gulp.src(paths.styles.src)
               .pipe(concat("index.css"))
               .pipe(cleanCss())
               .pipe(gulp.dest(paths.styles.dist))
    } 
    
    function scripts(){
        return  gulp.src(paths.scripts.src)
                .pipe(concat("index.js"))
                .pipe(babel({
                    presets:["@babel/env"]
                }))
                .pipe(uglify())
                .pipe(gulp.dest(paths.scripts.dist))
    }
    
    
    function html(){
        return gulp.src(paths.html.src)
               .pipe(gulp.dest(paths.html.dist))
               .pipe(connect.reload());
    }
    // function useconnect(){
    //     return connect.server({
    //         root : "./src",
    //         port : 8888,
    //         livereload: true
    //     });
    // }
    
    // function watch(){
    //     gulp.watch(paths.styles.src,styles);
    //     gulp.watch(paths.scripts.src,scripts);
    //     gulp.watch(paths.html.src,html);
    // }
    
    
    let build = gulp.series(html,styles,scripts);
    return build;
}

exports.build = buildConfig();
exports.dev   = devConfig();
//exports.default = buildConfig();
